home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / RAVE SDK 1.5 MacOS / RaveDemo / MyHeader.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.2 KB  |  240 lines  |  [TEXT/CWIE]

  1.  
  2.  
  3. #include <Menus.h>
  4. #include <Events.h>
  5. #include <Fonts.h>
  6. #include <Windows.h>
  7. #include <TextEdit.h>
  8. #include <Dialogs.h>
  9. #include <SegLoad.h>
  10. #include <TextUtils.h>
  11. #include <ToolUtils.h>
  12. #include <Resources.h>
  13. #include <Timer.h>
  14. #include <Devices.h>
  15.  
  16. #include <fp.h>
  17. #include <QDOffscreen.h>
  18. #include <QD3D.h>
  19. #include "RAVE.h"
  20. #include <QD3DAcceleration.h>
  21. #include "utils.h"
  22.  
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26.  
  27.  
  28. #define menuBarID 128
  29.  
  30. #define appleMenuID 128
  31. #define fileMenuID 129
  32. #define editMenuID 130
  33. #define engineMenuID 131
  34. #define optionsMenuID 132
  35. #define antialiasingMenuID 133
  36. #define textureFilterMenuID 134
  37.  
  38. #define miQuit (((long)fileMenuID << 16) + 6)
  39.  
  40. #define CheckMem(p) if(!p) DebugStr("\pOut of memory");
  41.  
  42. #define MYCALLOC(pointer, count) (pointer) = calloc(sizeof (*(pointer)), count); CheckMem(pointer)
  43. #define MYMALLOC(pointer, count) (pointer) = malloc(sizeof (*(pointer)) * count); CheckMem(pointer)
  44. #define MYREALLOC(pointer, count) (pointer) = realloc(pointer, sizeof (*(pointer)) * count); CheckMem(pointer)
  45. #define MYFREE(pointer) free(pointer); pointer = NULL
  46.  
  47.  
  48. // types
  49. typedef struct {
  50.     float x, y, z;
  51. } MyVector;
  52.  
  53.  
  54. typedef struct {
  55.     long pointNumber;
  56.     float u;
  57.     float v;
  58. } MyVert;
  59.  
  60. typedef struct {
  61.     MyVert corner[3];
  62.     short texture;
  63. } MyTri;
  64.  
  65.  
  66. typedef struct {
  67.     MyVector x;
  68.     MyVector y;
  69.     MyVector z;
  70.     MyVector w;
  71. } MyMatrix;
  72.  
  73.  
  74. typedef struct {
  75.     long bufferSize;
  76.     long count;
  77.     TQAVTexture * list;
  78. } VList;
  79.  
  80. typedef struct {
  81.     long bufferSize;
  82.     long count;
  83.     TQAIndexedTriangle * list;
  84. } TList;
  85.  
  86. typedef struct {
  87.     long bufferSize;
  88.     long count;
  89.     TQAIndexedTriangle * list;
  90. } TList2;
  91.  
  92.  
  93. typedef struct {
  94.     float d;    // the distance to the near clipping plane
  95.     float f;    // the distance to the far clipping plane
  96.     float h;    // half of the view width at distance d from camera
  97.     
  98.     unsigned int doubleBuffer : 1;
  99.     unsigned int noZBuffer : 1;
  100.     unsigned int perspectiveZ : 1;
  101.     unsigned int active : 1;
  102.     unsigned int useMemoryDevice : 1;
  103.     unsigned int useTriMeshes : 1;
  104.     unsigned int saveTransTris : 1;  // save transpearant(sp?) trtangles
  105.     unsigned int needsSync : 1;
  106.  
  107.     short textureFilter;
  108.     short antialiasing;
  109.  
  110.     char * errorMessage;
  111.  
  112.     MyVector lightVector;
  113.     float ambient;
  114.  
  115.     TQAEngine *engine;
  116.     short engineNumber;
  117.     
  118.     TQADrawContext *drawContext;
  119.     
  120.     WindowPtr window;
  121.     Rect viewRect;
  122.     float viewHeight;
  123.     float viewWidth;
  124.     
  125.     GWorldPtr backBuffer;
  126.     RgnHandle visRegion;
  127.     
  128.     TList * tList;
  129.     TList * currentTList;
  130.     VList vList;        // an allocated buffer of textureCount VList structs
  131.     
  132.     long triangleCount;
  133.  
  134.     long shieldRectCookie;
  135.     
  136. } MyState;
  137.  
  138.  
  139. void UpdateMyMenus(WindowPtr w);
  140. void MyTestSetup(void);
  141. void SetupNewWindow(void);
  142. void UnloadTextures(void);
  143. void DrawFrame(MyState *state);
  144. void HandleOtherMenu(short menuID, short menuItem);
  145. void WindowChanged(WindowPtr theWindow);
  146. void ClosingWindow(WindowPtr theWindow);
  147.  
  148.  
  149.  
  150. float MyDotProduct(MyVector * v1, MyVector * v2);
  151. // v3 = v1 - v2
  152. void MyVectorSubtract(MyVector * v1, MyVector * v2, MyVector * v3);
  153. void MyVectorAdd(MyVector * v1, MyVector * v2, MyVector * v3);
  154. // v2 = f * v1
  155. void MyVectorMultiply(float f, MyVector * v1, MyVector * v2);
  156. // v3 = v1 - v2
  157. // taken from 3D Computer Graphics by Alan Watt, p19
  158. void MyCalculateReflection(MyVector * l, MyVector * n, MyVector * r);
  159. void MyVectorCrossProduct(MyVector * v1, MyVector * v2, MyVector * v3);
  160.  
  161. #define HYPOT3(a, b, c) sqrt((a) * (a) + (b) * (b) + (c) * (c))
  162. float MyVectorLength(MyVector * v1);
  163. float MyVectorNormalize(MyVector * v1, MyVector * v2);
  164. float MyVectorDistance(const MyVector * v1, const MyVector * v2);
  165.  
  166.  
  167.  
  168. void mtest(void);
  169. void MyMatrixClear(MyMatrix * m1);
  170. void MyMatrixCat(MyMatrix * m1, MyMatrix * m2, MyMatrix * m3);
  171. void MyMatrixRotateByMatrix(MyMatrix * m1, MyMatrix * m2);
  172. void MyMatrixTransformVector(MyMatrix * m1, MyVector * v1, MyVector * v2);
  173. void MyMatrixRotateVector(MyMatrix * m1, MyVector * v1, MyVector * v2);
  174. void MyMatrixSetRotateX(float theta, MyMatrix * m1);
  175. void MyMatrixSetRotateY(float theta, MyMatrix * m1);
  176. void MyMatrixSetRotateZ(float theta, MyMatrix * m1);
  177. void MyMatrixNegate(MyMatrix * m1, MyMatrix * m2);
  178. void MyMatrixScaleLocal(MyMatrix * m1, float scaleFactor, MyMatrix * m2);
  179.  
  180.  
  181.  
  182. typedef struct {
  183.     long pointCount;
  184.     MyVector * pointList;
  185.     long triangleCount;
  186.     MyTri * triangleList;
  187.     float maxDimention;
  188.     
  189.     short normalMode;        // 0 for pervertex or 1 for flat shading
  190.     long * normalTable;        // the number of entries is  triangleCount for flat shading or triangleCount * 3 for per vertex shading
  191.     long normalCount;
  192.     MyVector * normalList;
  193. } MyShape;
  194.  
  195.  
  196. typedef struct {
  197.     MyShape * shape;
  198.     MyMatrix pos; // the position of the object
  199.     unsigned int backfaceCulling : 1;
  200.     float alpha;
  201. } MyObject;
  202.  
  203.  
  204.  
  205.  
  206. MyShape * MyShapeNew(void);
  207. void MyShapeDispose(MyShape * shape);
  208. MyShape * MyShapeLoad(char * fileName);
  209. void MyShapeSave(MyShape * shape, char * fileName);
  210. void MyShapeCalculateNormals(MyShape * shape, short mode);
  211.  
  212. void WriteGlobe(void);
  213. void WriteCylinder(void);
  214.  
  215. typedef struct {
  216.     float roll;
  217.     float pitch;
  218.     float yaw;
  219.     MyMatrix camera;    
  220.     unsigned char unusedKey;
  221.     unsigned int stopObjects : 1;
  222. } GlobalState;
  223.  
  224.  
  225. extern GlobalState globalState;
  226.  
  227.  
  228. #define charUp            0x1E
  229. #define charDown        0x1F
  230. #define charLeft        0x1C
  231. #define charRight        0x1D
  232. #define charPageUp        0x0B
  233. #define charPageDown    0x0C
  234. #define charSpace        0x20
  235. #define charESC            0x1B
  236. #define charReturn        0x0D
  237.  
  238.  
  239.  
  240.